package com.johnny.springai.flightbooking.service;


import com.johnny.springai.flightbooking.module.BookingDetail;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class FlightBookingService {


    // 模拟数据库存储
    private Map<String, BookingDetail> bookingDatabase = new HashMap<>();

    // 初始化一些模拟数据
    public FlightBookingService() {
        // 添加一些示例预订信息
        bookingDatabase.put("TKT001", new BookingDetail(
                "TKT001",
                "John Smith",
                "AA123",
                "New York",
                "Los Angeles",
                "2023-12-15 08:30",
                "2023-12-15 11:45",
                "12A",
                "Confirmed",
                450.00
        ));

        bookingDatabase.put("TKT002", new BookingDetail(
                "TKT002",
                "Emily Johnson",
                "DL456",
                "Chicago",
                "Miami",
                "2023-12-16 14:20",
                "2023-12-16 17:35",
                "25B",
                "Confirmed",
                320.50
        ));

        bookingDatabase.put("TKT003", new BookingDetail(
                "TKT003",
                "汪咪",
                "CA789",
                "北京",
                "上海",
                "2023-12-17 09:15",
                "2023-12-17 11:30",
                "08C",
                "Confirmed",
                850.00
        ));

        bookingDatabase.put("TKT004", new BookingDetail(
                "TKT004",
                "张伟",
                "MU567",
                "广州",
                "成都",
                "2023-12-18 13:45",
                "2023-12-18 16:20",
                "15F",
                "Pending",
                720.25
        ));

        bookingDatabase.put("TKT005", new BookingDetail(
                "TKT005",
                "李娜",
                "CZ345",
                "深圳",
                "西安",
                "2023-12-19 07:50",
                "2023-12-19 10:15",
                "22A",
                "Confirmed",
                680.75
        ));
    }


    public String cancelBooking(String ticketNumber, String name) {
        BookingDetail booking = bookingDatabase.get(ticketNumber);
        if (booking != null && booking.getPassengerName().equals(name)) {
            booking.setBookingStatus("Cancelled");
            return "Booking cancelled successfully for ticket number: " + ticketNumber;
        }
        return "Booking not found or name does not match";
    }

    public BookingDetail getBookingDetails(String ticketNumber,String passengerName) {
        BookingDetail booking = bookingDatabase.get(ticketNumber);
        if (booking != null && booking.getPassengerName().equals(passengerName)) {
            return booking;
        }
        return null;
    }
}
